<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Math对象</title>
    <script>
        // 利用对象封装自己的数学对象，里面有PI最大值和最小值
        /* var myMath = {
            PI: 3.1415926535,
            max: function() {
                var max = arguments[0];
                for (var i = 1; i < arguments.length; i++) {
                    if (arguments[i] > max) {
                        max = arguments[i];
                    }
                }
                return max;
            },
            min: function() {
                var min = arguments[0];
                for (var i = 1; i < arguments.length; i++) {
                    if (arguments[i] < min) {
                        min = arguments[i];
                    }
                }
                return min;
            }
        }
        console.log(myMath.PI);
        console.log(myMath.max(1, 3, 2, 4));
        console.log(myMath.min(1, 3, 2, 4)); */

        // 2.猜数字游戏
        function getRandom(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
        var num = getRandom(1, 50);
        var count = 0;
        while (a != num) {
            var a = prompt('请输入你猜的数字');
            if (a < num && count < 10) {
                count++;
                alert('你猜小了,还有' + (10 - count) + '次机会');
            } else if (a > num && count < 10) {
                count++
                alert('你猜大了，还有' + (10 - count) + '次机会');
            } else if (a == num && count < 10) {
                alert('恭喜你，猜对了');
            }
            if (count >= 10) {
                alert('你已经猜了10次，机会用完了');
                break;
            }

        }
    </script>
</head>

<body>

</body>

</html>